package com.sm42.goodsService.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.sm42.baseService.impl.BaseCrmpServiceImpl;
import com.sm42.goodsEntity.Brand;
import com.sm42.goodsService.BrandService;
import com.sm42.mapper.goodsMapper.BrandMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Service
public class BrandServiceImpl extends BaseCrmpServiceImpl<Brand> implements BrandService {
    @Autowired
    private BrandMapper brandMapper;

    @Override
    public List<Brand> findBrandList(String brand) {
        QueryWrapper<Brand> wrapper = new QueryWrapper<>();
        wrapper.eq("brand_name",brand);
        List<Brand> brands = brandMapper.selectList(wrapper);
        return brands;
    }

    @Override
    public Brand findBrandById(Long id) {
        return findById(id);
    }

    @Override
    public int deleteBrandById(Long id) {
        return deleteById(id);
    }

    @Override
    public int updateBrand(Brand brand) {
        brand.setUpdateTime(LocalDateTime.now());
        return update(brand);
    }

    @Override
    public int addBrand(Brand brand) {
        brand.setCreateTime(LocalDateTime.now());
        return add(brand);
    }

    @Override
    public List<Brand> findSearch(Brand brand) {
        QueryWrapper<Brand> wrapper = new QueryWrapper<>();
        wrapper.eq((brand.getBrandId() != 0),"brand_id",brand.getBrandId())
                .like(ObjectUtils.isNotNull(brand.getBrandName()),"brand_name",brand.getBrandName());
        List<Brand> brands = brandMapper.selectList(wrapper);
        return brands;
    }
}
